package com.cds.alert.action;

import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.cds.alert.ibatis.Criteria;
import com.cds.alert.pojo.AlertReport;
import com.cds.alert.service.AlertReportService;
import com.opensymphony.xwork2.Preparable;

public class AlertReportAction extends BaseAction implements Preparable {

	private static final long serialVersionUID = 1298568792435266728L;
	private Long id;
	private List<AlertReport> alertReports;
	private AlertReport alertReport;
	private Integer maxLength = 10;

	@Autowired
	private AlertReportService alertReportService;

	public void setId(Long id) {
		this.id = id;
	}

	public List<AlertReport> getAlertReports() {
		return alertReports;
	}

	public AlertReport getAlertReport() {
		return alertReport;
	}

	public void setAlertReport(AlertReport alertReport) {
		this.alertReport = alertReport;
	}

	public void prepare() throws Exception {
		if (getRequest().getMethod().equalsIgnoreCase("post")
				&& (!"".equals(getRequest().getParameter("alertReport.id")))) {
			alertReport = alertReportService.selectByPrimaryKey(id);
		}
	}

	public String delete() {

		return SUCCESS;
	}

	public String edit() throws IOException {

		return SUCCESS;
	}

	public String execute() {
		return SUCCESS;
	}

	public String cancel() {
		if (!"list".equals(from)) {
			return "home";
		}
		return "cancel";
	}

	public String save() throws Exception {
		return SUCCESS;
	}

	/** 报表订阅 */
	public String list() {
		Criteria criteria = new Criteria();
		criteria.setMysqlOffset(0);
		criteria.setMysqlLength(maxLength);
		alertReports = alertReportService.queryByExample(criteria);
		return SUCCESS;
	}

}
